package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Word;
import com.qf.enums.OAExceptionEnum;
import com.qf.exception.OAException;
import com.qf.mapper.WordgyhMapper;
import com.qf.service.WordgyhService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 程云
 * @Date 2019/12/13 11:46
 * 人生在世 代码二字
 */
@Slf4j
@Service
public class WordgyhServiceImpl implements WordgyhService {

    @Autowired
    private WordgyhMapper wordgyhMapper;

    @Override
    public PageInfo<Word> findAllRecycle(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Word> wordList = wordgyhMapper.findAllRecycle();
        PageInfo<Word> pageInfo = new PageInfo<>(wordList);
        return pageInfo;
    }

    @Override
    @Transactional
    public Integer del(Integer id) {
        Integer count = wordgyhMapper.deleteByPrimaryKey(id);
        if (count != 1){
            log.info("【删除回收站】 删除失败 count = {}",count);
            throw new OAException(OAExceptionEnum.TRIP_DELETE_ERROR.getCode(),OAExceptionEnum.TRIP_DELETE_ERROR.getMsg());
        }
        return count;
    }

    @Override
    @Transactional
    public Integer huan(Integer id) {
        Integer count = wordgyhMapper.huan(id);
        if(count != 1){
            log.info("【还原信息】 还原失败 count = {},id = {}", count,id);
            throw new OAException(OAExceptionEnum.HUAN_YUAN_ERROR.getCode(),OAExceptionEnum.HUAN_YUAN_ERROR.getMsg());
        }
        return count;
    }

    @Override
    @Transactional
    public int deletes(int[] wordId) {
        return wordgyhMapper.deletes(wordId);
    }

    @Override
    @Transactional
    public List<Word> findbyids(int[] wordId) {
        return wordgyhMapper.findbyids(wordId);
    }

}
